#include <bits/stdc++.h>

using namespace std;

int t;
int n, m;
int a[100005];
int c[100005];
string s[20];

int main() {
	freopen("arena.in", "r", stdin);
	freopen("arena.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= m; i++)
		cin >> c[i];
	const int k = 32 - __builtin_clz(n - 1);
	for (int i = 0; i < k; i++)
		cin >> s[i];
	for (cin >> t; t--; ) {
		long long res = 0;
		for (int i = 1; i <= m; i++) {
			int x = c[i];
			while (x != (x & -x))
				x += x & -x;
			res ^= 1LL * x * (x + 1) / 2 * i;
		}
		cout << res << '\n';
	}
	return 0;
}
